<template>
  <div id="active-type-form-container">
    <h3>{{ row.id == 0 ? "新增活动类型" : "修改活动类型" }}</h3>
    <el-form :model="row" class="form-area">
      <el-form-item>
        <el-input placeholder="请输入类型名称" v-model="row.name"></el-input>
      </el-form-item>
      <el-form-item class="btn">
        <el-button type="primary" @click="handleSave">保存</el-button>
        <el-button @click="handleCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {modifyRole, addNewRole, addActivityType, modifyActivityType} from "../api/index";
export default {
  name: "roleForm",
  props: {
    row: {
      type: Object,
      default() {
        return {
          id: 0,
          name: "",
        };
      }
    }
  },
  data() {
    return {};
  },
  methods: {
    handleCancel() {
      this.$emit("formCancel");
    },
    handleSave() {
      console.log(this.row);
      const callback = res => {
        // console.log(res.data);
        if (res.data.code == 0) {
          this.$message({
            type: "success",
            message: "保存成功",
            duration: 1500,
            onClose: () => {
              this.handleCancel();
              this.$emit("reloadData");
            }
          });
        } else {
          this.$message({
            type: "error",
            message: res.data.msg,
            duration: 1500
          });
        }
      };
      if (this.row.id == 0) {
        addActivityType(this.row).then(callback);
      } else {
        modifyActivityType(this.row).then(callback);
      }
    }
  }
};
</script>

<style scoped>
#active-type-form-container {
  width: 500px;
  height: 200px;
  background: #fff;
  position: absolute;
  bottom: 50%;
  left: 40%;
  transform: translate(-40%, 50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 8px;
}

#active-type-form-container h3 {
  align-self: flex-start;
  margin-left: 30px;
  margin-top: 20px;
  flex: 1;
}

#active-type-form-container .form-area {
  flex: 3;
}

.btn {
  margin-left: 100px;
}
</style>
